home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / argparser.e next >
Encoding:
Text File  |  1999-06-30  |  1.7 KB  |  75 lines

  1. /* *********** */
  2. /* argparser.e */
  3. /* *********** */
  4.  
  5.  
  6.  
  7. /*
  8.     WBBump - Bumpmapping on the Workbench!
  9.  
  10.     Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software Foundation,
  24.     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26.  
  27.  
  28. /*
  29.     helper module for parsing args
  30. */
  31.  
  32.  
  33. OPT MODULE
  34.  
  35.  
  36. MODULE    'dos/dos'
  37. MODULE    'dos/rdargs'
  38.  
  39.  
  40.  
  41. EXPORT PROC parseargs(template,array,string) HANDLE
  42.     DEF    rdargs=NIL:PTR TO rdargs,
  43.         tempstr=NIL:PTR TO CHAR,
  44.         templen
  45.  
  46.     IF string[StrLen(string)-1] <> 10
  47.         templen := StrLen(string)
  48.         tempstr := NewR(templen+2)
  49.         CopyMem(string,tempstr,templen+1)
  50.         tempstr[templen] := 10
  51.     ELSE
  52.         tempstr := string
  53.     ENDIF
  54.  
  55.     IF (rdargs := AllocDosObject(DOS_RDARGS,NIL)) = NIL THEN Raise("MEM")
  56.  
  57.     rdargs.source.buffer := tempstr
  58.     rdargs.source.length := StrLen(tempstr)
  59.     rdargs.source.curchr := NIL
  60.     rdargs.dalist := NIL
  61.     rdargs.flags := RDAF_NOPROMPT
  62.  
  63.     IF ReadArgs(template,array,rdargs) = NIL THEN Raise("ARGS")
  64.  
  65. EXCEPT DO
  66.     IF exception THEN RETURN 0
  67. ENDPROC rdargs
  68.  
  69. EXPORT PROC freeargs(rdargs)
  70.     IF rdargs <> NIL
  71.         FreeArgs(rdargs)
  72.         IF rdargs THEN FreeDosObject(DOS_RDARGS,rdargs)
  73.     ENDIF
  74. ENDPROC
  75.